﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tier3CommonDALLifeIt;
using System.Drawing;

namespace Life_It_CenProForm
{
    public partial class Promocion : Form
    {
        private List<Tier3CommonDALLifeIt.V_RFID_ARTICULOS> listaArticulos;
        private string cliente;
        private int cont = 0;
        private int entero = 0;

        public Promocion()
        {
            InitializeComponent();
        }
        

        public Promocion(List<V_RFID_ARTICULOS> listaArticulos, string cliente)
        {
            // TODO: Complete member initialization
            InitializeComponent();
            this.listaArticulos = listaArticulos;
            this.cliente = cliente;

            this.lblNombreCliente.Text = cliente;
            this.ptbIzquierda.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(202)))), ((int)(((byte)(1)))), ((int)(((byte)(56)))));
            mostrarListaProductos();
            
        }

        public void Salir() {
            this.Close();
        }


        private void mostrarListaProductos()
        {
            if (this.cont >= 3) {
                this.ptbIzquierda.BackColor = System.Drawing.Color.Transparent;
            }

            if (listaArticulos.Count > this.cont)
            {
                entero = (listaArticulos.Count - this.cont) / 3;
                if (entero > 0)
                {
                    this.cont++;
                    this.ptbArriba.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                    this.ptbArriba.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                    this.ptbArriba.Dock = System.Windows.Forms.DockStyle.Fill;
                    this.ptbArriba.Margin = new System.Windows.Forms.Padding(0);
                    this.lblPrecioArriba.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;                    
                    this.lblOfertaArriba.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                    this.lblNombreArriba.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                    this.tlpArticuloArriba.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;
                    

                    this.cont++;
                    this.ptbMedio.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                    this.ptbMedio.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                    this.ptbMedio.Dock = System.Windows.Forms.DockStyle.Fill;
                    this.ptbMedio.Margin = new System.Windows.Forms.Padding(0);
                    this.lblPrecioMedio.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;
                    this.lblOfertaMedio.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                    this.lblNombreMedio.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                    this.tlpArticuloMedio.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;

                    this.cont++;
                    this.ptbAbajo.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                    this.ptbAbajo.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                    this.ptbAbajo.Dock = System.Windows.Forms.DockStyle.Fill;
                    this.ptbAbajo.Margin = new System.Windows.Forms.Padding(0);
                    this.lblPrecioAbajo.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;
                    this.lblOfertaAbajo.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                    this.lblNombreAbajo.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                    this.tlpArticuloAbajo.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;
                }
                else
                {
                    switch ((listaArticulos.Count - this.cont) % 3)
                    {
                        case 1:
                            this.cont += 1;
                            this.ptbArriba.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                            this.ptbArriba.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                            this.ptbArriba.Dock = System.Windows.Forms.DockStyle.Fill;
                            this.ptbArriba.Margin = new System.Windows.Forms.Padding(0);
                            this.lblNombreArriba.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                            this.lblPrecioArriba.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;                    
                            this.lblOfertaArriba.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                            this.tlpArticuloArriba.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;
                            this.lblPrecioMedio.Text = "";
                            this.lblOfertaMedio.Text = "";
                            this.lblPrecioAbajo.Text = "";
                            this.lblOfertaAbajo.Text = "";
                            this.ptbMedio.BackgroundImage = null;
                            this.ptbAbajo.BackgroundImage = null;
                            this.ptbAbajo.Enabled = false;
                            this.ptbMedio.Enabled = false;
                            this.tlpArticuloMedio.BackgroundImage = null;
                            this.tlpArticuloAbajo.BackgroundImage = null;
                            break;
                        case 2:
                            this.cont += 1;
                            this.ptbArriba.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                            this.ptbArriba.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                            this.ptbArriba.Dock = System.Windows.Forms.DockStyle.Fill;
                            this.ptbArriba.Margin = new System.Windows.Forms.Padding(0);
                            this.lblNombreArriba.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                            this.lblPrecioArriba.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;                    
                            this.lblOfertaArriba.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                            this.tlpArticuloArriba.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;

                            this.cont++;
                            this.ptbMedio.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                            this.ptbMedio.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                            this.ptbMedio.Dock = System.Windows.Forms.DockStyle.Fill;
                            this.ptbMedio.Margin = new System.Windows.Forms.Padding(0);
                            this.lblNombreMedio.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                            this.lblPrecioMedio.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;                    
                            this.lblOfertaMedio.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                            this.tlpArticuloMedio.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;
                            this.lblPrecioAbajo.Text = "";
                            this.lblOfertaAbajo.Text = "";
                            this.ptbAbajo.BackgroundImage = null;
                            this.ptbMedio.Enabled = false;
                            this.tlpArticuloAbajo.BackgroundImage = null;
                            break;
                        case 3:
                            this.cont++;
                            this.ptbArriba.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                            this.ptbArriba.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                            this.ptbArriba.Dock = System.Windows.Forms.DockStyle.Fill;
                            this.ptbArriba.Margin = new System.Windows.Forms.Padding(0);
                            this.lblNombreArriba.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                            this.lblPrecioArriba.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;                    
                            this.lblOfertaArriba.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                            this.tlpArticuloArriba.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;

                            this.cont++;
                            this.ptbMedio.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                            this.ptbMedio.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                            this.ptbMedio.Dock = System.Windows.Forms.DockStyle.Fill;
                            this.ptbMedio.Margin = new System.Windows.Forms.Padding(0);
                            this.lblNombreMedio.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                            this.lblPrecioMedio.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;                    
                            this.lblOfertaMedio.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                            this.tlpArticuloMedio.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;

                            this.cont++;
                            this.ptbAbajo.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + this.cont + ".jpg");
                            this.ptbAbajo.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                            this.ptbAbajo.Dock = System.Windows.Forms.DockStyle.Fill;
                            this.ptbAbajo.Margin = new System.Windows.Forms.Padding(0);
                            this.lblNombreAbajo.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                            this.lblPrecioAbajo.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;                    
                            this.lblOfertaAbajo.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                            this.tlpArticuloAbajo.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;
                            break;
                    }
                }
                if (this.cont == listaArticulos.Count)
                {
                    this.ptbDerecha.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(202)))), ((int)(((byte)(1)))), ((int)(((byte)(56)))));
                }
            }
        }

        private void ptbImg_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Catalogo catalogo = new Catalogo();
            if (!this.ptbDerecha.BackColor.Equals(System.Drawing.Color.FromArgb(((int)(((byte)(202)))), ((int)(((byte)(1)))), ((int)(((byte)(56))))))){
                catalogo.ShowDialog();
            }
        }

        private void Promocion_Load(object sender, EventArgs e) {

        }

        private void Promocion_Resize(object sender, EventArgs e) { 
            
        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            mostrarListaProductos();
        }

        private void ptbIzquierda_Click(object sender, EventArgs e)
        {
            if (!usersession.SessionAlive)
            {
                this.Close();
                this.Dispose();
            }
            else 
            {
                mostrarListaProductosIzquierda();
                usersession.ResetTimer();
            }
            
        }

        private void mostrarListaProductosIzquierda()
        {

            if (this.cont > 3)
            {
                this.ptbDerecha.BackColor = System.Drawing.Color.Transparent;
                if (this.cont % 3 == 0)
                {
                    this.cont -= 3;
                }
                else
                {
                    this.cont -= (this.cont % 3);
                }

                this.ptbAbajo.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + (this.cont) + ".jpg");
                this.ptbAbajo.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                this.ptbAbajo.Dock = System.Windows.Forms.DockStyle.Fill;
                this.ptbAbajo.Margin = new System.Windows.Forms.Padding(0);
                this.ptbAbajo.Enabled = true;
                this.lblNombreAbajo.Text = listaArticulos[this.cont - 1].DESCRIPCION;
                this.lblPrecioAbajo.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;
                this.lblOfertaAbajo.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                this.tlpArticuloAbajo.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;

                this.ptbMedio.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + (this.cont - 1) + ".jpg");
                this.ptbMedio.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                this.ptbMedio.Dock = System.Windows.Forms.DockStyle.Fill;
                this.ptbMedio.Margin = new System.Windows.Forms.Padding(0);
                this.lblNombreMedio.Text = listaArticulos[this.cont - 2].DESCRIPCION;
                this.lblPrecioMedio.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;
                this.lblOfertaMedio.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                this.ptbMedio.Enabled = true;
                this.tlpArticuloMedio.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;

                this.ptbArriba.BackgroundImage = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures) + @"\promociones_" + (this.cont - 2) + ".jpg");
                this.ptbArriba.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                this.ptbArriba.Dock = System.Windows.Forms.DockStyle.Fill;
                this.ptbArriba.Margin = new System.Windows.Forms.Padding(0);
                this.lblNombreArriba.Text = listaArticulos[this.cont - 3].DESCRIPCION;
                this.lblPrecioArriba.Text = "Antes: S/. " + listaArticulos[this.cont - 1].PRECIO_ORIGINAL;
                this.lblOfertaArriba.Text = "S/. " + listaArticulos[this.cont - 1].PRECIO_FINAL;
                this.ptbArriba.Enabled = true;
                this.tlpArticuloArriba.BackgroundImage = global::Life_It_CenProForm.Properties.Resources.plantilla_promociones21;


                if (this.cont == 3) this.ptbIzquierda.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(202)))), ((int)(((byte)(1)))), ((int)(((byte)(56)))));

            }
        }

        private void ptbDerecha_Click(object sender, EventArgs e)
        {
            
            if (!usersession.SessionAlive)
            {
                this.Close();
                this.Dispose();
            }
            else 
            {
                mostrarListaProductos();
                usersession.ResetTimer();
            }
            
        }

        private void tlpArticulos_Paint(object sender, PaintEventArgs e)
        {

        }

        private void ptbArriba_Click(object sender, EventArgs e)
        {
            if (!usersession.SessionAlive)
            {
                this.Close();
                this.Dispose();
            }
            else
            {
                usersession.ResetTimer();
                string nombre = this.lblNombreArriba.Text;
                Catalogo catalogo = new Catalogo(nombre, this);
                catalogo.ShowDialog();
                if (!usersession.SessionAlive)
                {
                    this.Close();
                    this.Dispose();
                }
                else 
                {
                    usersession.ResetTimer();
                }
            }
          
        }

        private void ptbMedio_Click(object sender, EventArgs e)
        {
            string nombre = this.lblNombreMedio.Text;
            Catalogo catalogo = new Catalogo(nombre, this);
            catalogo.ShowDialog();
        }

        private void ptbAbajo_Click(object sender, EventArgs e)
        {
            string nombre = this.lblNombreAbajo.Text;
            Catalogo catalogo = new Catalogo(nombre, this);
            catalogo.ShowDialog();
            
        }

    }
}
